#version 300 es

#ifdef GL_ES
precision mediump float;
#endif

#define PI 3.14159265359

uniform vec2 u_resolution;

out vec4 outColor;

vec3 colorA = vec3(0.14, 0.14, 0.9);
vec3 colorB = vec3(1.0, 0.8, 0.22);

float plot(float y, float pct){
  return smoothstep(pct - 0.02, pct, y) -
        smoothstep(pct, pct+0.02, y);
}

void main()
{
  float solution = min(u_resolution.x, u_resolution.y);
  vec2 st = (gl_FragCoord.xy - u_resolution / 2.0) / solution;
  vec2 s = vec2(1.0, 1.0) - step(0.5, abs(st)); 
  if(s.x * s.y < 0.00001){
    discard;
  }
  st = st + vec2(0.5, 0.5);


  vec3 color = mix(colorA, colorB, st.x);

  float r = smoothstep(0.1, 0.9, st.x);
  float g = sin(PI * st.x);
  float b = pow(st.x, 0.5);

  color = mix(color, vec3(1.0, 0.0, 0.0), plot(st.y, r));
  color = mix(color, vec3(0.0, 1.0, 0.0), plot(st.y, g));
  color = mix(color, vec3(0.0, 0.0, 1.0), plot(st.y, b));

  outColor = vec4(color, 1);
}